package com.uinnova.product.eam.mvc;

import com.alibaba.fastjson.JSONObject;
import com.binary.framework.web.RemoteResult;
import com.uinnova.product.eam.comm.model.es.EamCategory;
import com.uinnova.product.eam.service.CyAutoCreateService;
import com.uinnova.product.eam.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/category")
public class CyAutoCreateController {

    @Autowired
    private CyAutoCreateService cyAutoCreateService;

    @GetMapping("/create/auto")
    public RemoteResult create() {
        cyAutoCreateService.categoryAutoCreate();
        return new RemoteResult("success");
    }

    @PostMapping("/create")
    public RemoteResult create(@RequestBody CyCreateReq req) {
        cyAutoCreateService.categoryCreate(req);
        return new RemoteResult("success");
    }

    @PostMapping("/check/assert/dir")
    public RemoteResult checkAssertDir(@RequestBody CheckAssertDirReq req) {
        CheckAssertDirRes res = cyAutoCreateService.checkAssertDir(req);
        return new RemoteResult(res);
    }

    @PostMapping("/get/assert/dir")
    public RemoteResult getAssertDir(@RequestBody String body) {
        JSONObject json = JSONObject.parseObject(body);
        String ciCode = json.getString("ciCode");
        Long privateDirId = cyAutoCreateService.getAssertDir(ciCode);
        return new RemoteResult(privateDirId);
    }

    @PostMapping("/get/assert/dirInfo")
    public RemoteResult getAssertDirInfo(@RequestBody String body) {
        JSONObject json = JSONObject.parseObject(body);
        String ciCode = json.getString("ciCode");
        Map<String, Object> dirInfo = cyAutoCreateService.getAssertDirInfo(ciCode);
        return new RemoteResult(dirInfo);
    }

    @PostMapping("/assert/checkout/info")
    public RemoteResult assertCheckoutInfo(@RequestBody AssertCheckoutReq req) {
        AssertCheckoutRes res = cyAutoCreateService.assertCheckoutInfo(req);
        return new RemoteResult(res);
    }

    @PostMapping("/archive/auto")
    public RemoteResult archive(@RequestBody String body) {
        JSONObject json = JSONObject.parseObject(body);
        String year = json.getString("year");
        cyAutoCreateService.archiveCategory(year);
        return new RemoteResult("success");
    }

}
